package com.dwb.controller;


import com.dwb.entity.PNewsColumn;
import com.dwb.result.Result;
import com.dwb.service.PNewsColumnService;
import com.dwb.utils.Empty;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author wx
 * @create 2020/6/28 10:40
 */
@RestController
@Api(value = "PNewsColumnController", description = "新闻栏目分类控制器")
@RequestMapping("/PNewsColumnController")
public class PNewsColumnController {

    @Autowired
    private PNewsColumnService sNewsColumnService;

    /**
     * 获取分类的详情信息
     *
     * @param parameters
     * @return
     */
    @PostMapping("/getInfo")
    @ApiOperation(value = "getInfo", notes = "查看分类的详情信息")
    public Result<PNewsColumn> getInfo(@RequestBody Map<String, String> parameters) {
        Result<PNewsColumn> result = Result.newSuccess();
        PNewsColumn sewsColumn = sNewsColumnService.getInfo(parameters);
        result.setDataMap(sewsColumn);
        return result;

    }

    /**
     * 获取分类列表
     *
     * @return
     */
    @ApiOperation(value = "getList", notes = "获取分类列表")
    @PostMapping("/getList")
    public Result<PageInfo<PNewsColumn>> getList(@RequestBody Map<String, String> parameters) {
        Result<PageInfo<PNewsColumn>> result = Result.newSuccess();
        PageInfo<PNewsColumn> sNewsColumn = sNewsColumnService.getList(parameters);
        result.setDataMap(sNewsColumn);
        return result;

    }

    /**
     * 根据id判断添加或者修改服务栏目分类详情
     *
     * @return
     */
    @PostMapping("/addOrUpdate")
    @ApiOperation(value = "addOrUpdate", notes = "添加OR修改服务栏目分类")
    public Result<String> add(@RequestBody PNewsColumn sNewsColumn) {
        if (Empty.INT_EMPTY(sNewsColumn.getId())) {
            sNewsColumnService.insert(sNewsColumn);
        } else {
            sNewsColumnService.update(sNewsColumn);
        }

        return Result.newSuccess();

    }

    /**
     * 根据id删除栏目分类详情
     *
     * @return
     */
    @ApiOperation(value = "delete")
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody Map<String, String> parameters) {
        sNewsColumnService.delete(parameters);
        return Result.newSuccess();


    }
}
